home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / save_key.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-26  |  1.1 KB  |  59 lines

  1. /*
  2.    save_key: save the key for this line in the history file so that
  3.    we can use it next run.
  4.  
  5.    Assume that the keyword file is opened and that the pipeline has
  6.    already been placed in the file.  We place the data in the file in
  7.    the following format:
  8.  
  9.    pipeline
  10.    \tkey_value
  11.    \t\tname value
  12.     .
  13.     .
  14.     .
  15.  
  16.    Side effect: return the actual key value for other parts of the
  17.    program to use.
  18.  
  19.    Kenneth Ingham
  20.  
  21.    Copyright (C) 1987 The University of New Mexico
  22. */
  23.  
  24. #include "defs.h"
  25.  
  26. save_key(cmd, line, key_val, hf)
  27. struct cmd_st *cmd;
  28. char *line, *key_val;
  29. FILE *hf;
  30. {
  31.     extern int vflag;
  32.  
  33.     if (cmd->key == NULL) { /* no key; no reason to save. */
  34.         if (vflag) 
  35.             printf("%s has no key field.\n",cmd->pipeline);
  36.         return;
  37.     }
  38.  
  39.     switch (cmd->out_fmt->type) {
  40.         case RELATIVE:
  41.             (void) get_rel_field(line,
  42.                 cmd->key->out_fmt.rel_fmt->field,
  43.                 key_val);
  44.             break;
  45.         case COLUMN:
  46.             (void) get_col_field(line,
  47.                 cmd->key->out_fmt.col_fmt->start,
  48.                 cmd->key->out_fmt.col_fmt->end, key_val);
  49.             break;
  50.     }
  51.             
  52.     if (!key_val[0]) {
  53.         if (vflag)
  54.             printf("the key field for %s is empty\n",cmd->pipeline);
  55.         return;
  56.     }
  57.     fprintf(hf, "\t%s\n",key_val);
  58. }
  59.